package com.resrun.model;

import com.resrun.vo.request.CAAuditRequest;
import com.resrun.vo.request.CARequestRequest;
import lombok.Data;

import java.util.Date;

/**
 * 证书申请请求参数
 *
 * @author hupan
 * @since 2024-01-23
 */
@Data
public class CARequest {

    /**
     * 主键ID
     */
    private Long id;

    /**
     * 证书类型 1=个人证书 2=企业证书
     */
    private Byte certType;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 企业ID
     */
    private Long enterpriseId;

    /**
     * 通用名称
     */
    private String commonName;

    /**
     * 国家/地区
     */
    private String country;

    /**
     * 组织
     */
    private String organization;

    /**
     * 组织单位
     */
    private String organizationUnit;

    /**
     * 省/市/自治区
     */
    private String province;

    /**
     * 城市/地点
     */
    private String locality;

    /**
     * 电子邮件
     */
    private String email;

    /**
     * 申请状态：0=未审核 1=审核通过 2=审核不通过
     */
    private Byte state;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;


    public static CARequest of(CARequestRequest request) {
        CARequest caRequest = new CARequest();
        caRequest.setCertType(request.getCertType());
        caRequest.setUserId(request.getUserId());
        caRequest.setEnterpriseId(request.getEnterpriseId());
        caRequest.setCommonName(request.getCommonName());
        caRequest.setCountry(request.getCountry());
        caRequest.setOrganization(request.getOrganization());
        caRequest.setOrganizationUnit(request.getOrganizationUnit());
        caRequest.setProvince(request.getProvince());
        caRequest.setLocality(request.getLocality());
        caRequest.setEmail(request.getEmail());

        return caRequest;
    }

    public static CARequest of(CAAuditRequest request) {
        CARequest caRequest = new CARequest();
        caRequest.setId(request.getRequestId());
        caRequest.setState(request.getState());

        return caRequest;
    }

}
